package com.sxjh.controller.pub;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sxjh.common.BaseController;
import com.sxjh.common.Result;
import com.sxjh.entity.Users;
import com.sxjh.entity.param.UsersListParam;
import com.sxjh.entity.result.UsersListResult;
import com.sxjh.service.UsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author zixin
 * @since 2021-07-31
 */
@RestController
@RequestMapping("/users")
@Api(tags = "用户")
public class UsersController extends BaseController {

  @Autowired
  private UsersService usersService;

  @ApiOperation("查询用户列表")
  @GetMapping
  Result<List<UsersListResult>> list(UsersListParam param) {
    LambdaQueryWrapper<Users> wrapper = new LambdaQueryWrapper<>();
    if (param.getId() != null) wrapper.eq(Users::getId, param.getId());
    if (StrUtil.isNotEmpty(param.getName())) wrapper.like(Users::getName, param.getName());
    List<Users> list = usersService.list(wrapper);
    return ok(copyList(list, UsersListResult::new));
  }

}

